package com.nondo.rdp.stock.repository;

import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.stock.domain.SimulateBuy;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface SimulateBuyRepository extends JpaRepository<SimulateBuy, Long>, JpaSpecificationExecutor<SimulateBuy> {
    @Query("select a from SimulateBuy a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<SimulateBuy> findOne(@Param("id") int id);

    @Modifying
    @Query("update SimulateBuy set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    SimulateBuy save(SimulateBuy simulateBuy);

    SimulateBuy findByCodeAndDelFlag(String code, String delFlag);

    SimulateBuy findByCodeAndUserAndDelFlag(String code, User user, String delFlag);
}
